package com.zhiche.lisa.bms.service.statistics.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.zhiche.lisa.bms.dao.mapper.statistics.StaticOrderMapper;
import com.zhiche.lisa.bms.dao.model.statistics.StaticOrder;
import com.zhiche.lisa.bms.dao.model.statistics.StaticOrderComposite;
import com.zhiche.lisa.bms.service.statistics.StaticOrderCompositeService;
import com.zhiche.lisa.bms.service.statistics.StaticOrderService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单统计表 服务实现类
 * </p>
 *
 * @author liangpeng
 * @since 2019-01-18
 */
@Service
public class StaticOrderServiceImpl extends ServiceImpl<StaticOrderMapper, StaticOrder> implements StaticOrderService {

    @Autowired
    private StaticOrderCompositeService orderCompositeService;

    /**
     * 同步订单到统计表中
     */
    @Override
    public void syncOrderToComposite() {
        List<StaticOrder> notExistCompositeOrderList = baseMapper.getNotExistCompositeOrderList();
        if (CollectionUtils.isNotEmpty(notExistCompositeOrderList)) {
            List<StaticOrderComposite> orderCompositeList = Lists.newArrayList();
            notExistCompositeOrderList.forEach(order -> {
                StaticOrderComposite orderComposite = new StaticOrderComposite();
                BeanUtils.copyProperties(order, orderComposite);
                orderCompositeList.add(orderComposite);
            });
            if (CollectionUtils.isNotEmpty(orderCompositeList)) {
                orderCompositeService.insertBatch(orderCompositeList);
            }
        }

    }
}
